<!DOCTYPE html>
<html>
<head>
    <title>{{title}}</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    <style type="text/css" media="screen">
        body {background-color: #f5f5f5}
    </style>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-xs-12">
                <h2 class="text-capitalize">{{title}}</h2>
                <p class='attribute'><strong>Start Time: </strong>{{headers.start_time}}</p>
                <p class='attribute'><strong>Duration: </strong>{{headers.duration}}</p>
                <p class='attribute'><strong>Status: </strong>{{headers.status}}</p>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <p style="text-align: right;"><button id="all" class="btn btn-primary btn-xs">ALL</button>&nbsp;&nbsp;<button id="pass" class="btn btn-success btn-xs">PASS</button>&nbsp;&nbsp;<button id="fail" class="btn btn-danger btn-xs">FAIL</button>&nbsp;&nbsp;<button id="skip" class="btn btn-info btn-xs">SKIP</button>&nbsp;&nbsp;<button id="error" class="btn btn-warning btn-xs">ERROR</button></p>
                <table class='table table-hover table-responsive'>
                    <thead>
                        <tr>
                            <th class="col-xs-3">TestCase</th>
                            <th class="col-xs-4">ClassName</th>
                            <th class="col-xs-2">Expected</th>
                            <th class="col-xs-1">Time&nbsp;&nbsp;(Rerun)</th>
                            <th class="col-xs-2">Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for eachTestCase, className,expected, status, errorType, errorMessage, times, rerun, screenshot in tests_results %}
                            <tr class="{{status}}">
                                <td>{{eachTestCase}}</td>
                                <td>{{className}}</td>
                                <td>{{expected}}</td>
                                <td>{{times}}&nbsp;&nbsp;({{rerun}})</td>
                                <td>
                                    <span class="label label-{{status}}">
                                        {% if "success" == status %}
                                            Pass
                                        {% elif "info" == status %}
                                            Skip
                                        {% elif "danger" == status%}
                                            Fail
                                        {% else %}
                                            Error
                                        {% endif %}
                                    </span>
                                    {% if "success" not in status %}
                                        &nbsp;<button class="btn btn-default btn-xs">View</button>
                                    {% endif %}
                                    {% if screenshot != '' %}
                                        &nbsp;<a href="{{screenshot}}" target="_blank" class="btn btn-primary btn-xs">Screenshot</a>
                                    {% endif %}
                                </td>
                            </tr>
                            {% if "success" != status %}
                                <tr style="display:none;" class="{{status}}-detail">
                                    <td colspan="5">
                                        <p>{{errorType}}</p>
                                        <p><b>ErrorMessage:</b>&nbsp;{{errorMessage}}</p>
                                    </td> 
                                </tr>
                            {% endif %}
                        {% endfor %}
                        <tr style="font-weight: bold;">
                            <td>
                               Total Test Runned: {{total_tests}}
                            </td>
                            <td></td>
                            <td></td>
                            <td colspan="2">
                                <span>{{headers.status}}</span>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('td').on('click', 'button.btn-default', function(e){
                e.preventDefault();
                var $this = $(this);
                var $nextRow = $this.closest('tr').next('tr');
                $nextRow.slideToggle("fast");
                $this.text(function(i, text){
                    if (text === 'View') {
                        return 'Hide';
                    } else {
                        return 'View';
                    };
                });
            });
            $('#all').click(function(){
                $('tr.success,tr.danger,tr.warning,tr.info').removeAttr('style');
                $('tr.success-detail,tr.danger-detail,tr.warning-detail,tr.info-detail').attr('style', 'display: none;');
                $('button.btn-default').text('View');
            });
            $('#pass').click(function(){
                $('tr.danger,tr.warning,tr.info').attr('style', 'display: none;');
                $('tr.success').removeAttr('style');
                $('tr.success-detail,tr.danger-detail,tr.warning-detail,tr.info-detail').attr('style', 'display: none;');
                $('button.btn-default').text('View');
            });
            $('#fail').click(function(){
                $('tr.success,tr.warning,tr.info').attr('style', 'display: none;');
                $('tr.danger').removeAttr('style');
                $('tr.success-detail,tr.danger-detail,tr.warning-detail,tr.info-detail').attr('style', 'display: none;');
                $('button.btn-default').text('View');
            });
            $('#skip').click(function(){
                $('tr.danger,tr.warning,tr.success').attr('style', 'display: none;');
                $('tr.info').removeAttr('style');
                $('tr.success-detail,tr.danger-detail,tr.warning-detail,tr.info-detail').attr('style', 'display: none;');
                $('button.btn-default').text('View');
            });
            $('#error').click(function(){
                $('tr.danger,tr.success,tr.info').attr('style', 'display: none;');
                $('tr.warning').removeAttr('style');
                $('tr.success-detail,tr.danger-detail,tr.warning-detail,tr.info-detail').attr('style', 'display: none;');
                $('button.btn-default').text('View');
            });
        });
    </script>
</body>
</html>
